package com.jredu.controller.client;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jredu.entity.User;
import com.jredu.service.UserService;

@Controller
@RequestMapping("/api")
public class UserClientController {
	@Autowired
	private UserService userService;

	@RequestMapping(value = "/users", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
	@ResponseBody
	public List<User> findUsers() {
		return userService.findUsers();
	}

	@RequestMapping(value = "/users/{id}", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
	@ResponseBody
	public User findUserById(@PathVariable(value = "id") Integer id) {
		return userService.findUserById(id);
	}

	@RequestMapping(value = "/users", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
	@ResponseBody
	public String addUser(User user) {

		return "{msg:ok}";
	}

	@RequestMapping(value = "/users/{id}", 
			method = RequestMethod.DELETE,
			produces = "application/json;charset=utf-8")
	@ResponseBody
	public String deleteUser(
			@PathVariable(value="id") Integer id) {

		return "{msg:ok}";
	}

}
